<?php

/**
 * Add your description here
 *
 * @author Doan Anh CNC
 * @copyright CNC Group
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

class Vina_Model_DeveloperMapper extends Vina_Model_UsersMapper {

    /**
     * $_dbTable - instance of Compa_Model_DbTable_ProceduresStep
     *
     * @var Compa_Model_DbTable_ProceduresStep     
     */
    protected $_dbTable;

    /**
     * finds a row where $field equals $value
     *
     * @param string $field
     * @param mixed $value
     * @param Compa_Model_ProceduresStep $cls
     */     
    public function TreeMenu($parentid = 0,$space = '-', $trees = NULL){ 
        $modelCat = new Vina_Model_Categories();
        if(!$trees) $trees = array(); 
        $dataCategory = $modelCat->fetchListToArray("category_id = $parentid", "id desc");
        
        foreach($dataCategory as $rs){
        $trees[] = array('category_id'=>$rs['category_id'], 'id'=>$rs['id'],'name'=>$space.$rs['name'], 'category_name'=>$modelCat->find($rs['category_id'])->name); 
        $trees = $this->TreeMenu($rs['id'],$space.'--',$trees); 
        } 
        return $trees; 
    
     }
     public function TreeMenuId($parentid = 0,$space = '-', $trees = NULL){ 
        $modelCat = new Vina_Model_Categories();
        if(!$trees) $trees = array(); 
        $dataCategory = $modelCat->fetchListToArray("category_id = $parentid", "id desc");
        $trees[] = $parentid;
        foreach($dataCategory as $rs){
        $trees[] = $rs['id']; 
        $trees = $this->TreeMenuId($rs['id'],$space.'--',$trees); 
        } 
        
        return $trees; 
    
     }     
     public function listSlideHome(){
           $db  = $this->getDbTable()->getDefaultAdapter();
           $select = "select Sl.*, Pro.description, Pro.description_en, Pro.description_china, Pro.weight, Pro.price, Pro.madein, Pro.name as product_name from slides Sl left join products Pro on Sl.product_id = Pro.id
           where Sl.status = 1";
          
           $data=$db->fetchAll($select);
           return $data;  
     }
     public function fetchListSchedule($where){
            $db  = $this->getDbTable()->getDefaultAdapter();
           $select = "select Sc.*,
           
           (select Ne.title from news Ne where Ne.id = Sc.news_id) as news_name from scheduling Sc
           where ".$where." order by Sc.time desc";
           $data=$db->fetchAll($select);
           return $data;
     }
}